import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '立可得', icon: 'fangzi' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/tablea',
    name: 'Example',
    meta: { title: '工单管理', icon: 'gongdanguanli' },
    children: [
      {
        path: 'tablea',
        name: 'Tablea',
        component: () => import('@/views/table/index'),
        meta: { title: '运营工单' }
      },
      {
        path: 'tree1a',
        name: 'Tree1a',
        component: () => import('@/views/tree/index'),
        meta: { title: '运维工单' }
      }
    ]
  },
  {
    path: '/point',
    component: Layout,
    redirect: '/point/tabled',
    name: 'point',
    meta: { title: '点位管理', icon: 'didiandingwei_o' },
    children: [
      {
        path: 'tabled',
        name: 'Tabled',
        component: () => import('@/views/point/point1'),
        meta: { title: '区域管理' }
      },
      {
        path: 'treed',
        name: 'Treed',
        component: () => import('@/views/point/point2'),
        meta: { title: '点位管理' }
      },
      {
        path: 'pointc',
        name: 'pointc',
        component: () => import('@/views/point/point3'),
        meta: { title: '合作商管理' }
      }
    ]
  },
  {
    path: '/equipment',
    component: Layout,
    redirect: '/equipment/tablee',
    name: 'equipment',
    meta: { title: '设备管理', icon: 'dianbiao' },
    children: [
      {
        path: 'tablee',
        name: 'Tablee',
        component: () => import('@/views/equipment/equip1'),
        meta: { title: '区域管理' }
      },
      {
        path: 'treee',
        name: 'Treee',
        component: () => import('@/views/equipment/equip2'),
        meta: { title: '点位管理' }
      },
      {
        path: 'pointa',
        name: 'pointa',
        component: () => import('@/views/equipment/equip3'),
        meta: { title: '合作商管理' }
      }
    ]
  },
  {
    path: '/Personnel',
    component: Layout,
    redirect: '/Personnel/table',
    name: 'Personnel',
    meta: { title: '人员管理', icon: 'renyuanguanli' },
    children: [
      {
        path: 'tableb',
        name: 'Tableb',
        component: () => import('@/views/Personnel/Person1'),
        meta: { title: '人员统计' }
      },
      {
        path: 'treeb',
        name: 'Treeb',
        component: () => import('@/views/Personnel/Person2'),
        meta: { title: '人效统计' }
      },
      {
        path: 'point2',
        name: 'point2',
        component: () => import('@/views/Personnel/Person3'),
        meta: { title: '工作量列表' }
      }
    ]
  },
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/table',
    name: 'goods',
    meta: { title: '商品管理', icon: 'shangpinguanli' },
    children: [
      {
        path: 'tablec',
        name: 'Tablec',
        component: () => import('@/views/goods/goodsTy'),
        meta: { title: '商品类型' }
      },
      {
        path: 'treec',
        name: 'Treec',
        component: () => import('@/views/goods/goodsm'),
        meta: { title: '商品管理' }
      }
    ]
  },
  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: '策略管理', icon: 'faguangdengpao' }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: '/index',
        name: 'order',
        component: () => import('@/views/order'),
        meta: { title: '订单管理', icon: 'dingdanguanli' }
      }
    ]
  },
  {
    path: '/statistical',
    component: Layout,
    children: [
      {
        path: '/statistical',
        name: 'statistical',
        component: () => import('@/views/statistical'),
        meta: { title: '对账统计', icon: 'duizhang' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
